home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 25 / Mac Magazin and MacEasy Magazine CD - Issue 25.iso / Online / Joe's-PPP-Scripts / PPP-plan-toggle / PPP-plan-toggle-as text < prev    next >
Text File  |  1996-08-21  |  5KB  |  163 lines

  1.  
  2. property openPlan : {""}
  3. property closePlan : {""}
  4.  
  5. global planFile, parsedPlanfile
  6. global planDialogtext, planFilelocation, intermediateResult
  7.  
  8. on run
  9.     if openPlan = {""} then
  10.         set planDialogtext to {"Select a file to be sent at OPEN connection:"}
  11.         getPlanlocation()
  12.         set openPlan to planFilelocation
  13.     end if
  14.     if closePlan = {""} then
  15.         set planDialogtext to {"Select a file to be sent at CLOSE connection:"}
  16.         getPlanlocation()
  17.         set closePlan to planFilelocation
  18.     end if
  19.     
  20.     if (PPPopened) then
  21.         set planFile to {""}
  22.         open for access file closePlan
  23.         set planFile to (read closePlan)
  24.         close access closePlan
  25.         dealwithPlanfile()
  26.         ftpPlanfile()
  27.         
  28.         closePPP with hard close
  29.         
  30.     else
  31.         
  32.         openPPP (getPPPServer)
  33.         
  34.         set planFile to {""}
  35.         open for access file openPlan
  36.         set planFile to (read openPlan)
  37.         close access openPlan
  38.         repeat while not (PPPopened)
  39.         end repeat
  40.         dealwithPlanfile()
  41.         ftpPlanfile()
  42.     end if
  43. end run
  44.  
  45. on getPlanlocation()
  46.     try
  47.         set planFilelocation to (choose file with prompt ¬
  48.             planDialogtext of type {"TEXT"}) as string
  49.     on error errMsg
  50.         abort()
  51.     end try
  52. end getPlanlocation
  53.  
  54. on dealwithPlanfile()
  55.     try
  56.         searchReplace of me into planFile at "%ip%" given replaceString:(tcp my address)
  57.         set intermediateResult to result as text
  58.     on error errMsg
  59.         abort()
  60.     end try
  61.     try
  62.         searchReplace of me into intermediateResult at "%clock%" given replaceString:(current date)
  63.         set parsedPlanfile to result as text
  64.     on error errMsg
  65.         abort()
  66.     end try
  67. end dealwithPlanfile
  68.  
  69. on searchReplace into mainString at searchString given replaceString:replaceString
  70.     
  71.     repeat while mainString contains searchString
  72.         set foundOffset to offset of searchString in mainString
  73.         set stringStart to text 1 thru (foundOffset - 1) of mainString
  74.         set stringEnd to text (foundOffset + (count of searchString)) thru -1 of mainString
  75.         set mainString to stringStart & replaceString & stringEnd
  76.     end repeat
  77.     return mainString
  78. end searchReplace
  79.  
  80. on ftpPlanfile()
  81.     set LF to (ASCII character of 10)
  82.     set CR to (ASCII character of 13)
  83.     set CRLF to CR & LF
  84.     try
  85.         set oldDelimiters to AppleScript's text item delimiters
  86.         set AppleScript's text item delimiters to {"."}
  87.         set localAddr to (tcp my address)
  88.         set localAddrList to text items of localAddr
  89.         set AppleScript's text item delimiters to {","}
  90.         set localAddrCommaString to localAddrList as string
  91.         set AppleScript's text item delimiters to oldDelimiters
  92.         set sss to (tcp connect to host (GetICPreference ftp host) port 21)
  93.         try
  94.             readresponse(sss)
  95.             
  96.             tcp write stream sss data "USER " & (GetICPreference mail account) & return using ISO88591
  97.             readresponse(sss)
  98.             
  99.             tcp write stream sss data "PASS " & (GetICPreference mail password) & return using ISO88591
  100.             readresponse(sss)
  101.             
  102.             tcp write stream sss data "TYPE A" & return using ISO88591
  103.             readresponse(sss)
  104.             
  105.             set data_stream to (tcp wait for connect)
  106.             set data_stream_status to (tcp status stream data_stream)
  107.             set portHiByte to round (local port of data_stream_status) / 256 rounding down
  108.             set portLoByte to (local port of data_stream_status) mod 256
  109.             
  110.             tcp write stream sss data "PORT " & localAddrCommaString & "," & portHiByte & "," & portLoByte & return using ISO88591
  111.             readresponse(sss)
  112.             
  113.             tcp write stream sss data "STOR .plan" & return & LF
  114.             readresponse(sss)
  115.             
  116.             repeat until (connection status of (tcp status stream data_stream) = Connected)
  117.             end repeat
  118.             tcp write stream data_stream data parsedPlanfile using ISO88591
  119.             
  120.             try
  121.             on error msg number num from obj partial result pr
  122.                 tcp close stream data_stream
  123.                 error msg number num from data_stream
  124.             end try
  125.             tcp close stream data_stream
  126.             readresponse(sss)
  127.             tcp write stream sss data "QUIT" & return using ISO88591
  128.             readresponse(sss)
  129.             tcp close stream sss
  130.             
  131.         on error msg number num from obj partial result pr
  132.             try
  133.                 tcp write stream sss data "QUIT" & return using ISO88591
  134.                 readresponse(sss)
  135.             on error
  136.             end try
  137.             
  138.             tcp close stream sss
  139.             error msg number num from obj partial result pr
  140.         end try
  141.     on error errMsg
  142.         abort()
  143.     end try
  144. end ftpPlanfile
  145.  
  146. on readresponse(sstream)
  147.     set LF to ASCII character (10)
  148.     repeat until (tcp ahead characters LF stream sstream)
  149.     end repeat
  150.     set serverResponse to (tcp read until characters LF stream sstream using ISO88591)
  151. end readresponse
  152.  
  153. on abort()
  154.     display dialog "Plan upload script aborted" buttons {"OK"} default button "OK"
  155.     set openPlan to {""}
  156.     set closePlan to {""}
  157.     quit
  158. end abort
  159.  
  160. on quit
  161.     continue quit
  162. end quit
  163.